<template>
<div>
  <div class="btn" @click="filterClick">
     <img src="~images/icon/filter.png" alt="" class="icon">
     筛选
  </div>
  <div class="filter" style="top:100%">
      <div class="header">筛选</div>
      <div class="scroll_wrap">
          <div class="categories">
              <div class="categories_title">彩种</div>
              <div class="categories_list">
                  <div class="categories_item_wrap" v-for="(item,index) in categories" :key="index">
                      <div class="categories_item" @click="categorieClick(index)" :class="[categorieIndex===index?'categories_item_active':'']">
                          <div class="text">{{item}}</div>
                      </div>
                  </div>
              </div>
          </div>
          <div class="time_picker">
              <div class="time_picker_title">
                  日期
                  <span>(以北京时间为准)</span>
              </div>
              <div class="quickly">
                  <div 
                    class="item" 
                    v-for="(item,index) in timeList" 
                    :key="index" 
                    @click='setTime(index)'
                    :class="[timeIndex===index?'item_active':'']"
                    >{{item}}
                  </div>
              </div>
              <div class="picker_wrap">
                  <div @click="popupTime('Start')">
                      <div class="picker">
                          <span style="float: right; color: rgb(136, 136, 136);">{{timeStart}} 08:00:00</span>
                      </div>
                  </div>
                  <div class="center"></div>
                  <div @click="popupTime('End')">
                      <div class="picker">
                          <span style="float: right; color: rgb(136, 136, 136);">{{timeEnd}} 07:59:59</span>
                      </div>
                  </div>
                  <div class="picker_hide"></div>
              </div>
          </div>
      </div>
      <div class="btns">
          <div class="confirm" @click='confirm'>确定</div>
          <div class="close" @click="close"></div>
      </div>
  </div>
  <van-popup v-model="show" position="bottom" :style="{ height: '40%' }">
      <van-datetime-picker
        v-model="currentDate"
        type="date"
        :formatter="formatter"
        :filter="filter"
        title="选择日期"
        @confirm="timeConfire"
        @cancel="show = false"
      />
  </van-popup>
  
</div>
</template>

<script>
export default {
  name: 'filterPage',
  data () {
    return {
      categories: [
        '一分快3', '广东快3', '香港快3', '台湾快3', '急速快3', '幸运快3', '十分六合彩', '急速时时彩', '极速快乐十分', '传统江苏快3',
        '传统上海快3', '传统安徽快3', '传统河北快3', '传统广西快3', '传统甘肃快3', '传统湖北快3', '传统北京快3', '澳门快3', '极速赛车', '极速飞艇',
        '传统重庆时时彩', '传统北京赛车', '传统江西快3', '香港六合彩'
      ],
      categorieIndex:-1,
      timeIndex:-1,
      timeStart:'起始时间',
      timeEnd:'截止时间',
      timeList:['今日','昨日','本周','上周'],
      currentDate: new Date(),
      show:false,
      timeType:null,
    }
  },
  methods: {
    categorieClick (index) {
        if(this.categorieIndex===index){
            this.categorieIndex = -1
        }else{
            this.categorieIndex = index
        }
    },
    setTime(index){
        if(this.timeIndex===index){
            this.timeIndex = -1;
            this.timeStart = '起始时间';
            this.timeEnd = '截止时间';
        }else{
            this.timeIndex = index;
            if(index===0){
                this.timeStart = this.util.timeFormat();
                this.timeEnd = this.util.timeFormat(1);
            }else if(index===1){
                this.timeStart = this.util.timeFormat(-1);
                this.timeEnd = this.util.timeFormat();
            }else{
                let day = new Date().getDay();
                day = day>5?5:day;
                day = index===2?day:(day+7);
                this.timeStart = this.util.timeFormat(-(day-1));
                this.timeEnd = this.util.timeFormat(5-day);
            }
            
        }
    },
    confirm(){
        this.$('.filter').css('top','100%');
    },
    close(){
        this.$('.filter').css('top','100%');
    },
    filterClick(){
        this.$('.filter').css('top','0px');
    },
    formatter(type, value) {
      if (type === 'year') {
        return `${value}年`;
      } else if (type === 'month') {
        return `${value}月`
      }else if(type === 'day'){
         return `${value}日` 
      }
      return value;
    },
    filter(type, options){
        if(type==="year"){
            return options.filter(option=>option===new Date().getFullYear().toString())
        }
        return options;
    },
    popupTime(type){
        this.timeType = type;
        this.show = true;
    },
    timeConfire(){
        this['time'+this.timeType] = this.currentDate.Format('yyyy-MM-dd');
        this.show = false;
    }
  },
  created () {}
}
</script>
<style lang="less" rel="stylesheet/less" scoped>
.btn {
    position:fixed;
    width: 72px;
    height: 30px;
    border-radius: 100px;
    -webkit-box-shadow: 0 0 10px rgba(127,74,137,.54);
    box-shadow: 0 0 10px rgba(127,74,137,.54);
    background-color: #8e61e5;
    color: #fff;
    display: -ms-flexbox;
    display: flex;
    -ms-flex-align: center;
    align-items: center;
    -ms-flex-pack: center;
    justify-content: center;
    font-size:12px;
    bottom:40px;
    right:40px;
}
.btn .icon {
    height: 12px;
    margin-right: 4px;
}
.filter {
    position: fixed;
    z-index: 999;
    width: 100%;
    height: 100%;
    top: 100%;
    bottom: 0;
    left: 0;
    right: 0;
    background: url("~images/logo/filterBg.png");
    background-size: 100% 100%;
    -webkit-transition: top .2s linear;
    -o-transition: top .2s linear;
    transition: top .2s linear;
    display: -ms-flexbox;
    display: flex;
    -ms-flex-direction: column;
    flex-direction: column;
}
.filter .header {
    height: 40px;
    display: -ms-flexbox;
    display: flex;
    -ms-flex-pack: center;
    justify-content: center;
    -ms-flex-align: center;
    align-items: center;
    font-size: 16px;
    color: #3f3f3f;
    margin: 10px 0;
}
.filter .scroll_wrap {
    -ms-flex: 1 1;
    flex: 1 1;
    height: 100%;
    min-height: 320px;
    display: -ms-flexbox;
    display: flex;
    -ms-flex-direction: column;
    flex-direction: column;
    -ms-flex-pack: center;
    justify-content: center;
}
.categories {
    width: 100%;
    height: 200px;
    overflow: hidden;
    display: -ms-flexbox;
    display: flex;
    -ms-flex-direction: column;
    flex-direction: column;
    margin-bottom: 40px;
}
.filter .scroll_wrap .categories .categories_title {
    font-size:12px;
    -webkit-box-sizing: border-box;
    box-sizing: border-box;
    padding-left: 40px;
    color: #661dac;
    margin-bottom: 8px;
}
.filter .scroll_wrap .categories .categories_list {
    overflow: scroll;
    -ms-flex: 1 1;
    flex: 1 1;
    width: 100%;
    height: 100%;
    display: -ms-flexbox;
    display: flex;
    -ms-flex-align: center;
    align-items: center;
    -ms-flex-wrap: wrap;
    flex-wrap: wrap;
    -webkit-box-sizing: border-box;
    box-sizing: border-box;
    border-top: 1px solid #ccc;
    border-bottom: 1px solid #ccc;
    overflow-x: hidden;
}
.filter .scroll_wrap .categories .categories_list .categories_item_wrap {
    -webkit-box-sizing: border-box;
    box-sizing: border-box;
    -ms-flex-preferred-size: 33.33333333%;
    flex-basis: 33.33333333%;
    display: -ms-flexbox;
    display: flex;
    -ms-flex-pack: center;
    justify-content: center;
    -ms-flex-align: center;
    align-items: center;
    margin: 4px 0;
}
.filter .scroll_wrap .categories .categories_list .categories_item_wrap .categories_item {
    width: 80%;
    height: 28px;
    display: -ms-flexbox;
    display: flex;
    -ms-flex-pack: center;
    justify-content: center;
    -ms-flex-align: center;
    align-items: center;
    border-radius: 100px;
    -webkit-box-sizing: border-box;
    box-sizing: border-box;
    background-color: #fff;
    color: #3f3f3f;
}
.filter .scroll_wrap .categories .categories_list .categories_item_wrap .categories_item .text {
    font-size:12px;
    width: 80%;
    white-space: nowrap;
    overflow: hidden;
    text-align: center;
    -webkit-box-sizing: border-box;
    box-sizing: border-box;
}
.filter .scroll_wrap .time_picker {
    margin-bottom: 40px;
}
.filter .scroll_wrap .time_picker .time_picker_title {
    -webkit-box-sizing: border-box;
    box-sizing: border-box;
    padding-left: 40px;
    color: #661dac;
    margin-bottom: 8px;
    font-size:12px;
}
.filter .scroll_wrap .time_picker .time_picker_title span {
    color: #888;
}
.filter .scroll_wrap .time_picker .quickly {
    display: -ms-flexbox;
    display: flex;
    -ms-flex-pack: center;
    justify-content: center;
    -ms-flex-align: center;
    align-items: center;
    margin: 0 0 16px;
    font-size:12px;
}
.filter .scroll_wrap .time_picker .quickly .item, .filter .scroll_wrap .time_picker .quickly .item_active {
    width: 52px;
    height: 24px;
    background-color: #fff;
    display: -ms-flexbox;
    display: flex;
    -ms-flex-pack: center;
    justify-content: center;
    -ms-flex-align: center;
    align-items: center;
    margin: 0 12px;
    border-radius: 100px;
    font-size:12px;
}
.filter .scroll_wrap .time_picker .picker_wrap, .filter .scroll_wrap .time_picker .picker_wrap .picker {
    display: -ms-flexbox;
    display: flex;
    -ms-flex-pack: center;
    justify-content: center;
    -ms-flex-align: center;
    align-items: center;
}
.filter .scroll_wrap .time_picker .picker_wrap .picker {
    width: 112px;
    padding: 4px;
    border: 1px solid #78707e;
    color: #ccc;
    background-color: #fff;
    border-radius: 4px;
    letter-spacing: 1px;
    font-size: 14px;
    line-height: 16px;
    text-align: center;
}
.filter .scroll_wrap .time_picker .picker_wrap .center {
    height: 2px;
    width: 20px;
    background-color: #3f3f3f;
    margin: 0 12px;
}
.filter .btns{
    display: flex;
    -ms-flex-align: center;
    align-items: center;
    flex: 0.5 1;
    min-height: 120px;
    -ms-flex-direction: column;
    flex-direction: column;
    -ms-flex-pack: distribute;
    justify-content: space-around;
}
.filter .btns .confirm {
    line-height: 44px;
    text-align: center;
    width: 125px;
    height: 44px;
    font-size: 15px;
    letter-spacing: 1px;
    border-radius: 100px;
    -ms-flex-pack: center;
    justify-content: center;
    background: -webkit-linear-gradient(-45deg,#ff78d2,#9067ff);
    color: #fff;
    -webkit-box-shadow: 0 3px 10px rgba(187,86,208,.54);
    box-shadow: 0 3px 10px rgba(187,86,208,.54);
}
.filter .btns .close {
    position: relative;
    width: 40px;
    height: 40px;
}
.filter .btns .close:after, .filter .btns .close:before {
    position: absolute;
    top: 0;
    bottom: 0;
    left: 0;
    right: 0;
    margin: auto;
    content: "";
    width: 20px;
    height: 1px;
    background: #666;
    transform: rotate(45deg);
}
 .filter .btns .close:after{
    transform: rotate(-45deg);
}
.categories_item_wrap .categories_item_active,.item_active{
    background-color: #661dac !important;
    color: #fff !important;
}
</style>
